package gui;

import gui.AESEncryptionCBCMode;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Font;

import javax.swing.JPanel;
import javax.swing.JFrame;
import java.awt.Dimension;
import javax.swing.JLabel;
import java.awt.Rectangle;
import javax.swing.JTabbedPane;
import java.awt.GridBagLayout;
import java.io.File;
import java.util.HashMap;

import javax.swing.ButtonGroup;
import javax.swing.JRadioButton;
import javax.swing.ImageIcon;
import javax.swing.JRootPane;
import javax.swing.JTextArea;
import javax.swing.JRadioButtonMenuItem;
import javax.swing.JButton;

import code.Language;
import code.Settings;

public class TripleDESEncryptionMode extends JPanel {
	
	Color c= new Color(0x80, 0x80, 0xFF);
	
	Color TAc = new Color(246, 250, 250);

	private static final long serialVersionUID = 1L;

	private JPanel jContentPane = null;

	private JLabel jLabel = null;

	private JTabbedPane jTabbedPane = null;

	private JPanel jPanel = null;
	
	ButtonGroup rbgroup = new ButtonGroup();  //  @jve:decl-index=0:

	private JRadioButton jRadioButton = null;

	private JRadioButton jRadioButton1 = null;

	private JRadioButton jRadioButton2 = null;

	private JRadioButton jRadioButton3 = null;

	private JLabel jLabel1 = null;

	private JLabel jLabel2 = null;

	private JLabel jLabel3 = null;

	private JLabel jLabel4 = null;

	private JLabel help = null;

	private JLabel help1 = null;

	private JLabel help2 = null;

	private JLabel help3 = null;

	private JLabel jLabel5 = null;

	ATOCOmain atocoframe;

	private JLabel jLabel6 = null;
	
	private String selected="ECB";  //  @jve:decl-index=0:

	private JTextArea jTextArea = null;
	
	private HashMap labels;
	private Settings s;

	/**
	 * This is the default constructor
	 */
	public TripleDESEncryptionMode(ATOCOmain atocoframe) {
		super();
		s = new Settings();
		Language l = new Language();
		labels = l.changeLanguage((String) s.global.get("language"), "TripleDESEncryptionMode", (String) s.global.get("installPath"));
		this.atocoframe=atocoframe;
		initialize();
		this.setPreferredSize( new Dimension( 400, 550 ) );
		
		
	    //this.getRootPane().setWindowDecorationStyle(JRootPane.PLAIN_DIALOG);
	}

	/**
	 * This method initializes this
	 * 
	 * @return void
	 */
	private void initialize() {
		this.setSize(819, 430);
		jLabel5 = new JLabel();
		jLabel5.setText((String) labels.get("jLabel5"));
		jLabel5.setForeground(c);
		jLabel5.setBounds(new Rectangle(525, 38, 77, 18));
		jLabel5.setFont(new java.awt.Font("Arial", Font.BOLD, 10));
		jLabel = new JLabel();
		jLabel.setBounds(new Rectangle(40, 16, 363, 34));
		jLabel.setText((String) labels.get("jLabel"));
		//jLabel.setForeground(c);
		this.setLayout(null);
		this.add(jLabel, null);
		this.add(getJTabbedPane(), null);
		this.setBackground(Color.WHITE);
	}

	/**
	 * This method initializes jContentPane
	 * 
	 * @return javax.swing.JPanel
	 */


	/**
	 * This method initializes jTabbedPane	
	 * 	
	 * @return javax.swing.JTabbedPane	
	 */
	private JTabbedPane getJTabbedPane() {
		if (jTabbedPane == null) {
			jTabbedPane = new JTabbedPane();
			jTabbedPane.setBounds(new Rectangle(35, 70, 745, 400));
			jTabbedPane.addTab("TripleDES", null, getJPanel(), null);
		}
		return jTabbedPane;
	}

	/**
	 * This method initializes jPanel	
	 * 	
	 * @return javax.swing.JPanel	
	 */
	private JPanel getJPanel() {
		if (jPanel == null) {
			jLabel6 = new JLabel(new ImageIcon((String) s.global.get("installPath") + File.separator + "images/en/nexticon.gif"));
			jLabel6.setBounds(new Rectangle(195, 202, 79, 38));
			jLabel6.setText((String) labels.get("jLabel6"));
			jLabel6.setForeground(c);
			jLabel6.addMouseListener(new java.awt.event.MouseAdapter() {   
				public void mouseClicked(java.awt.event.MouseEvent e) {  
					if(selected.equals("ECB"))
						atocoframe.contentPane(new TripleDESEncryptionECBMode(atocoframe));
					else if(selected.equals("CBC"))
						atocoframe.contentPane(new TripleDESEncryptionCBCMode(atocoframe));
					else if(selected.equals("CFB"))
						atocoframe.contentPane(new TripleDESEncryptionCFBMode(atocoframe));
					else if(selected.equals("OFB"))
						atocoframe.contentPane(new TripleDESEncryptionOFBMode(atocoframe));
				}
			
			});
			help3 = new JLabel();
			help3.setBounds(new Rectangle(245, 150, 25, 25));
			help3.setIcon(new ImageIcon((String) s.global.get("installPath") + File.separator + "images/en/questionmark.jpg", ""));
			help3.addMouseListener(new java.awt.event.MouseAdapter() {
				public void mouseClicked(java.awt.event.MouseEvent e) {
					//jTextArea.setVisible(true);
					jTextArea.setText((String) labels.get("ofb"));
				}
			});
			help2 = new JLabel();
			help2.setBounds(new Rectangle(245, 120, 25, 25));
			help2.setIcon(new ImageIcon((String) s.global.get("installPath") + File.separator + "images/en/questionmark.jpg", ""));
			help2.addMouseListener(new java.awt.event.MouseAdapter() {
				public void mouseClicked(java.awt.event.MouseEvent e) {
					//jTextArea.setVisible(true);
					jTextArea.setText((String) labels.get("cfb"));
				}
			});
			help1 = new JLabel();
			help1.setBounds(new Rectangle(245, 90, 25, 25));
			help1.setIcon(new ImageIcon((String) s.global.get("installPath") + File.separator + "images/en/questionmark.jpg", ""));
			help1.addMouseListener(new java.awt.event.MouseAdapter() {
				public void mouseClicked(java.awt.event.MouseEvent e) {
					//jTextArea.setVisible(true);
					jTextArea.setText((String) labels.get("cbc"));
				}
			});
			help = new JLabel();
			help.setBounds(new Rectangle(245, 60, 25, 25));
			help.setIcon(new ImageIcon((String) s.global.get("installPath") + File.separator + "images/en/questionmark.jpg", ""));
			help.addMouseListener(new java.awt.event.MouseAdapter() {
				public void mouseClicked(java.awt.event.MouseEvent e) {
					//jTextArea.setVisible(true);
					jTextArea.setText((String) labels.get("ecb"));
				}
			});
			jLabel4 = new JLabel();
			jLabel4.setBounds(new Rectangle(50, 150, 190, 25));
			jLabel4.setText("Output Feedback (OFB)");
			jLabel4.setForeground(c);
			jLabel4.addMouseListener(new java.awt.event.MouseAdapter() {   
				public void mouseClicked(java.awt.event.MouseEvent e) {  
					selected="OFB";
					jRadioButton3.setSelected(true);
				}
			
			});
			jLabel3 = new JLabel();
			jLabel3.setBounds(new Rectangle(50, 120, 190, 25));
			jLabel3.setText("Cipher Feedback (CFB)");
			jLabel3.setForeground(c);
			jLabel3.addMouseListener(new java.awt.event.MouseAdapter() {   
				public void mouseClicked(java.awt.event.MouseEvent e) {  
					selected="CFB";
					jRadioButton2.setSelected(true);
				}
			
			});
			jLabel2 = new JLabel();
			jLabel2.setBounds(new Rectangle(50, 90, 190, 25));
			jLabel2.setText("Cipher-block Chaining (CBC)");
			jLabel2.setForeground(c);
			jLabel2.addMouseListener(new java.awt.event.MouseAdapter() {   
				public void mouseClicked(java.awt.event.MouseEvent e) {  
					selected="CBC";
					jRadioButton1.setSelected(true);
				}
			
			});
			jLabel1 = new JLabel();
			jLabel1.setBounds(new Rectangle(50, 60, 190, 25));
			jLabel1.setText("Electronic Codebook (ECB)");
			jLabel1.setForeground(c);
			jLabel1.addMouseListener(new java.awt.event.MouseAdapter() {   
				public void mouseClicked(java.awt.event.MouseEvent e) {  
					selected="ECB";
					jRadioButton.setSelected(true);
				}
			
			});
			jPanel = new JPanel();
			jPanel.setLayout(null);
			jPanel.setBackground(Color.WHITE);
			jPanel.add(getJRadioButton(), null);
			jPanel.add(getJRadioButton1(), null);
			jPanel.add(getJRadioButton2(), null);
			jPanel.add(getJRadioButton3(), null);
			jPanel.add(jLabel1, null);
			jPanel.add(jLabel2, null);
			jPanel.add(jLabel3, null);
			jPanel.add(jLabel4, null);
			jPanel.add(help, null);
			jPanel.add(help1, null);
			jPanel.add(help2, null);
			jPanel.add(help3, null);
			jPanel.add(jLabel6, null);
			jPanel.add(jLabel5, null);
			jPanel.add(getJTextArea(), null);
		}
		return jPanel;
	}

	/**
	 * This method initializes jRadioButton	
	 * 	
	 * @return javax.swing.JRadioButton	
	 */
	
	
	private JRadioButton getJRadioButton() {
		if (jRadioButton == null) {
			jRadioButton = new JRadioButton();
			jRadioButton.setSelected(true);
			rbgroup.add(jRadioButton);
			jRadioButton.setBounds(new Rectangle(20, 60, 20, 20));
			jRadioButton.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					selected="ECB";
				}
			});
			
		}
		return jRadioButton;
	}

	/**
	 * This method initializes jRadioButton1	
	 * 	
	 * @return javax.swing.JRadioButton	
	 */
	private JRadioButton getJRadioButton1() {
		if (jRadioButton1 == null) {
			jRadioButton1 = new JRadioButton();
			jRadioButton1.setBounds(new Rectangle(20, 90, 20, 20));
			rbgroup.add(jRadioButton1);
			jRadioButton1.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					selected="CBC";
				}
			});
		}
		return jRadioButton1;
	}

	/**
	 * This method initializes jRadioButton2	
	 * 	
	 * @return javax.swing.JRadioButton	
	 */
	private JRadioButton getJRadioButton2() {
		if (jRadioButton2 == null) {
			jRadioButton2 = new JRadioButton();
			jRadioButton2.setBounds(new Rectangle(20, 120, 20, 20));
			rbgroup.add(jRadioButton2);
			jRadioButton2.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					selected="CFB";
				}
			});
		}
		return jRadioButton2;
	}

	/**
	 * This method initializes jRadioButton3	
	 * 	
	 * @return javax.swing.JRadioButton	
	 */
	private JRadioButton getJRadioButton3() {
		if (jRadioButton3 == null) {
			jRadioButton3 = new JRadioButton();
			jRadioButton3.setBounds(new Rectangle(20, 150, 20, 20));
			rbgroup.add(jRadioButton3);
			jRadioButton3.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					selected="OFB";
				}
			});
		}
		return jRadioButton3;
	}

	/**
	 * This method initializes jTextArea	
	 * 	
	 * @return javax.swing.JTextArea	
	 */
	private JTextArea getJTextArea() {
		if (jTextArea == null) {
			jTextArea = new JTextArea();
			jTextArea.setBounds(new Rectangle(425, 61, 258, 178));
			jTextArea.setBackground(TAc);
			jTextArea.setFont(new Font("Arial", Font.ITALIC, 12));
			jTextArea.setLineWrap(true);
			
//			scroll = new JScrollPane(jTextArea);
//			scroll.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
//			scroll.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
			jTextArea.setEditable(false);
		}
		return jTextArea;
	}

}  //  @jve:decl-index=0:visual-constraint="10,10"
